<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
	session_start();
	$dbconn = pg_connect("host=localhost port=5432 dbname=CinemaEnri user=postgres password=Quie1hoh");
	if (!$dbconn){
			die("Errore di connessione al database" . pg_last_error());
	}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="Css/screen.css" rel="stylesheet" type="text/css" media="screen"/>
<title>Cinema Enri - Pagina Personale</title>
</head>

<body>
<div id="logo"><img src="Images/Logo.jpg" width="220" height="100"/></div>
        <div id="Header">
             <div id="cerca">
                
            </div>
        </div>
        <div id="main">
            <div id="menu">
                <ul>
                	<div id="infoCinema">
                    	<div class="titolo">Info Cinema</div>
                        <li><a href="Index.php">Home</a></li>
                        <li><a href="Programmazione.php">Programmazione</a></li>
                    </div>
                     <?php
						$user=$_SESSION['User'];
						$admin=$_SESSION['Admin'];
						if (isset($user)){
					?>
                    <div id="utente">
                    	<div class="titolo">Servizi Utente</div>
                        <li><a href="Prenotazioni.php">Prenota un film</a></li>
                        <li><a href="PaginaPersonale.php">Pagina Personale</a></li>
                    </div>
                    <?php
						}
						if ($admin=="t"){
					?>
                    <div id="admin">
                    	<div class="titolo">Amministratore</div>
                        <li><a href="InsSpettacoli.php">Inserimento Spettacoli</a></li>
                        <li><a href="ModSpettacoli.php">Modifica Spettacoli</a></li>
                        <li><a href="InsFilm.php">Inserimento Film</a></li>
                        <li><a href="ModFilm.php">Modifica Film</a></li>
                        <li><a href="InsAttori.php">Inserimento Attori</a></li>
                        <li><a href="ModAttori.php">Modifica Attori</a></li>
                        <li><a href="InsProduzioni.php">Inserimento Produzioni</a></li>
                        <li><a href="ModPrenotazioni.php">Modifica Prenotazioni</a></li>
                    </div>
					<?php
						}
					?>
                <ul>
            </div>
            <div id="path">
            </div>
            <div id="content">
            	<h1>Tuoi / Modifica dati personali</h1>
                <?php 
				
					if ($admin=="t"){
						$qry = "SELECT * FROM \"tblUtenti\";";
						$result = pg_query($dbconn, $qry);	
						
						echo "<form action=PaginaPersonale.php method=POST >";
							echo "Modifica i dati di: <br/><br/><select onchange='" . 'window.location.href = "PaginaPersonale.php?Utente=" +
						 			this.options[this.selectedIndex].value;' . "' name=utente class=textfield>";
									echo "<option value=0 >------</option>";
					while($riga = pg_fetch_assoc($result)){
						if ($_GET['Utente'] == $riga['Login'])
							echo "<option value=".$riga['Login']." selected='selected'>".$riga['Login']."</option>";
						else
							echo "<option value=".$riga['Login'].">".$riga['Login']."</option>";
					}
					echo "</select><br />\n";	
								
						 echo "</form>";
						 
						 $qry = "SELECT * FROM \"tblUtenti\" WHERE \"Login\"='".$_GET['Utente']."';";
						 $result = pg_query($dbconn, $qry);	
							
					}
					if (isset($user) && $admin=="f"){
						$qry = "SELECT * FROM \"tblUtenti\" WHERE \"Login\"='".$user."';";
						$result = pg_query($dbconn, $qry);
					}
					
						echo "<form action=ModificaDatiPers.php method=POST >";
						while($riga = pg_fetch_assoc($result)) {
							
							echo "<h2>Login:</h2> <input type=text readonly=readonly name=login value=".$riga['Login']." />";
							echo "<h2>Nome:</h2> <input type=text name=nome value='".$riga['Nome']."' />";
							echo "<h2>Cognome:</h2> <input type=text name=cognome value='".$riga['Cognome']."' />";
							echo "<h2>Città:</h2> <input type=text name=citta value='".$riga['Citta']."' />";
							echo "<h2>Via:</h2> <input type=text name=via value='".$riga['Via']."' />";
							echo "<h2>CAP:</h2> <input type=text name=cap value=".$riga['CAP']." />";
							echo "<h2>Provincia:</h2> <input type=text name=provincia value=".$riga['Provincia']." />";
							echo "<h2>Password:</h2> <input type=text name=password value=".$riga['Password']." />";
							echo "<h2>Email:</h2> <input type=text name=email value=".$riga['Email']." />";
							
							echo "<br/> <br/><input type=submit value=modifica />";
							
						
						echo "</form>";
						
					}
				?>
            </div>
            
            <div id="menuDestro">
                <div id="login" >
                	<?php
						$user=$_SESSION['User'];
					 	if (isset($user)){
								echo "<h2>Stato</h2>";
								echo "<h3>Benvenuto ".$user."</h3>";
								echo "<a href=LogOut.php>LogOut</a>";
						}else{
					?>
                	<h2>Login</h2>
                	<form action="Index.php" method="post">
                    	Username:<input type="text" name="Username" />
                        Password:<input type="password" name="Password" />
                        <input type="submit" value="Login" />
                         Se non sei registrato: <a href="Registrazione.php" >Registrati</a>
                    </form>
                   <?php
						}
				   ?>
                </div>
            </div>
       </div>
</div>



</body>
</html>